﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Streambolics.Notes.Gui
{
    public partial class ItemList : UserControl
    {
        private int _Loading = 0;

        public ItemList ()
        {
            InitializeComponent ();
        }

        private void BeginUpdate ()
        {
            list.BeginUpdate ();
            _Loading++;
        }

        private void EndUpdate ()
        {
            list.EndUpdate ();
            _Loading--;
        }

        public void AddItem (string aName, string aValue)
        {
            ListViewItem i = list.Items.Add (aName);
            i.SubItems.Add (aValue);
        }
        public void SetDocument (Document aDocument)
        {
            BeginUpdate ();
            try
            {
                list.Items.Clear ();
                if (aDocument != null)
                {
                    foreach (string s in aDocument.ItemNames)
                    {
                        AddItem (s, aDocument.ItemText (s));
                    }
                 
                }
            }
            finally
            {
                EndUpdate ();
            }
        }
    }
}
